//针对全屏视频挡住弹幕的问题，一般做法是让video充满父容器，再让父容器全屏。
(function(){
    var show_barrage = function($container,content){
        console.log($container);
        $container.append("<h1 class='barrage' style='position:absolute; color:white; top:" + ($container.height() * Math.random()) + "px'>" + content+ "</h1>")
    }
    window.video_init = function($container,source,data){
        var stamp = new Date().getTime();
        $container.append("<div class='real_container" + stamp + "' style='height:480px; width:800px; background-color:black; position:relative'>")
        $container = $container.find('.real_container' + stamp);
        $container.append("<video src='" + source +"' controls style='position:absolute; height:480px; width:800px;'></video>")
        $cur_video = $container.find('video');
        $cur_video.on('timeupdate',function(){
            // console.log($(this)[0].currentTime);
            if($(this)[0].seeking === false){
                for (data_p in data) {
                    data_p = data[data_p];
                    // console.log(data_p);
                    if($(this)[0].currentTime >= data_p.time && data_p.shown === false){
                        show_barrage($container,data_p.content);
                        data_p.shown = true;
                    }
                }
            }
        })
        $cur_video.on('seeking',function(){
            // console.log('start');
            for (data_p in data) {
                data_p = data[data_p];
                data_p.shown = true;
            }
        });
        $cur_video.on('seeked',function(){
            console.log($(this)[0].currentTime);
            for (data_p in data) {
                data_p = data[data_p];
                if($(this)[0].currentTime <= data_p.time){
                    data_p.shown = false;
                }
            }
        })
    }
    window.set_timer = function(){
        setInterval(function(){
                $('.barrage').css('transform',function(){
                    if ($(this).offset().left >= $(this).parent().width()){
                        $(this).remove();
                    }else{
                        return 'translateX(' + ($(this).offset().left + 5) + 'px)';
                    }
                });
        },30);
    }
}).call(this);